<?php
namespace Admin\Controller;

class ActorMovieController extends AdminController
{
	//主演管理首页
	public function index ()
	{
		$id =I('get.id/d');
		$data = M ('actor')->field('mid,name,aid')->where('mid='.$id)->join('lamp_actor_movie on lamp_actor.id=lamp_actor_movie.aid')->select();
		//var_dump($data);exit;
		if (!$data) {
			$this->assign ('row','暂无搜索内容...');
		}
		$this->assign ('list',$data);
		$this->assign ('d',$id);
		$this->display ();
	}
	//主演管理添加页
	public function add ()
	{
		$mid = I('get.mid/d');
		$this->assign ('mid',$mid);
		$this->display();
	}
	public function insert ()
	{
		// exit;
		//var_dump($_POST);exit;
		$info = M('actor')->field('id')->where('name="'.$_POST['name'].'"')->find();
		//var_dump($info);exit;
		if (!$info) {
			$this->error ('没有此演员,请先到演员管理添加');
			exit;
		}
		$info['mid'] = $_POST['mid'];
		$info['aid'] = $info['id'];
		//var_dump($info);exit;
		$actormovie = D ('actor_movie');
		if (!$actormovie->create ($info)) {
			$this->error ($actormovie->getError ());
		} else {
			//var_dump($actormovie->create($info));exit;
			if ($actormovie->add () > 0) {
				$this->success ('添加成功',U('ActorMovie/index',array('id'=>$_POST['mid'])));
			} else {
				$this->error ('添加失败');
			}
		}
	}
	public function edit ()
	{
		$data = $_GET;
		$data['name'] = M('actor')->field('name')->find($data['aid']);
		//var_dump($data);exit;
		$this->assign ('list',$data);
		$this->display ();
	}
	public function update ()
	{
		//var_dump($_POST);exit;
		$info = M('actor')->field('id')->where('name="'.$_POST['name'].'"')->find();
		//var_dump($info);exit;
		if (!$info) {
			$this->error ('没有此演员,请先到演员管理添加');
			exit;
		}
		
		//var_dump($info);exit;
		$actormovie = D ('actor_movie');
		if (!$actormovie->create ($data)) {
			$this->error ($actormovie->getError ());
		} else {
			// var_dump($actormovie->create ());
			// var_dump( $actormovie->save());exit;
			if ($actormovie->save ()!==false) {
				$this->success ('修改成功',U('ActorMovie/index',array('id'=>$_POST['mid'])));
			} else {
				$this->error ('修改失败');
			}
		}
	}
	public function delete ()
	{
		//var_dump($_GET);exit;
		$aid = I ('get.aid/d');
		$mid = I ('get.mid/d');
		//var_dump($aid);exit;
		if (M('actor_movie')->where(' mid='.$mid.' and aid='.$aid)->delete () > 0) {
			$this->success ('删除成功');
		} else {
			$this->error ('删除失败');
		}
	}
}